class_name CardPile extends Resource

signal card_pile_size_changed(cards_amount: int)

@export var cards: Array[Card] = []

func empty() -> bool:
	return cards.is_empty()
	
func draw_card() -> Card:
	var card = cards.pop_front()
	card_pile_size_changed.emit(cards.size())
	return card
	
func add_card(card: Card) -> void:
	cards.append(card)
	card_pile_size_changed.emit(cards.size())
	
func shuffle() -> void:
	RNG.shuffle(cards)
	
func clear() -> void:
	cards.clear()
	card_pile_size_changed.emit(cards.size())


func duplicate_cards() -> Array[Card]:
	var new_array: Array[Card] = []
	for card in cards:
		new_array.append(card.duplicate())
	return new_array


func custom_duplidate() -> CardPile:
	var new_card_pile := CardPile.new()
	new_card_pile.cards = duplicate_cards()
	return new_card_pile

func _to_string() -> String:
	var _cards_string: PackedStringArray = []
	for i in range(cards.size()):
		_cards_string.append("%d: %s" % [i + 1, cards[i].id])
	return "\n".join(_cards_string)
